package org.estela.comp;

public final class DataType {

	public static final int BOOLEAN = 0;
	
	public static final int CLASSIFIER = 1;

	public static final int DATASET = 2;
	
	public static final int DOUBLE = 3;

	public static final int INSTANCE = 4;
	
	public static final int INT = 5;
	
	public static final int CLASS = 6;
	
	public static final int USER_DEFINED = 7;
	
	public static final int VOID = 8;

	public static final int STRING = 9;
	
	

	private String userDefinedType;

	private int type = -1;
	
	private int arrayDim = -1;
	
	public DataType(int type) {
		this.checkType(type);
		this.type = type;
	}
	
	public DataType(int type, String userDefinedType) {
		this(type);
		this.userDefinedType = userDefinedType;
	}

 	public DataType() {
		// TODO Auto-generated constructor stub
	}

	private void checkType(int type) {
		if (type < 0 || type > 10) {
			throw new IllegalArgumentException("Invalid type: " + type);
		}
	}

	public String getUserDefinedType() {
		return userDefinedType;
	}

	public void setUserDefinedType(String userDefinedType) {
		this.userDefinedType = userDefinedType;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}
	
	
	public String toString() {
		StringBuilder buff = new StringBuilder(getClass().getName());
		buff.append("@[type=").append(this.getTypeAsString());
		if (this.userDefinedType != null) {
			buff.append(", userDefinedType=").append(this.userDefinedType);
		}
		buff.append(']');
		return buff.toString();
	}

	private String getTypeAsString() {
		switch (this.type) {
		case BOOLEAN: return "boolean";
		case CLASSIFIER: return "classifier";
		case DATASET: return "dataset";
		case DOUBLE: return "double";
		case INSTANCE: return "instance";
		case INT: return "int";
		case CLASS: return "class";
		}
		return null;
	}

	public int getArrayDim() {
		return this.arrayDim;
	}

	public void setArrayDim(int arrayDim) {
		this.arrayDim = arrayDim;
	}

	public boolean isArray() {
		return this.arrayDim != -1;
	}

}
